package com.sdc.autohome.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @ClassName:DateUtils
 * @Auther: Liu
 * @Date: 2024/11/28 20:24
 */

public class DateUtils {
    public static String dateUtily(){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");

        // 获取当前日期
        Date currentDate = new Date();

        // 创建一个Calendar实例
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(currentDate);

        // 将日期向前推一天
        calendar.add(Calendar.DAY_OF_MONTH, -1);

        // 获取前一天的日期
        Date previousDate = calendar.getTime();

        // 格式化前一天的日期
        String previousDateString = sdf.format(previousDate);

        System.out.println("前一天的日期是：" + previousDateString);
        return previousDateString;
    }
}
